package pack0831;
//sleep 睡眠时不会打开锁
//wait 等待时会打开锁，执行wait时需要唤醒,如不唤醒，后面的程序不执行
public class DemoF {
    public static void main(String[] args) throws Exception{
        DemoF0 df0 = new DemoF0();
        DemoF1 df1 = new DemoF1(df0);
        DemoF2 df2 = new DemoF2(df0);
        df1.start();
        Thread.sleep(1000);
        df2.start();
    }
}
class DemoF0{
    public synchronized void a(int i){
        System.out.println("aaaa"+i);
        try {
            //Thread.sleep(10000);
            wait();
        }catch (Exception e){}
        System.out.println("8888");
    }
}
class DemoF1 extends Thread{
    private DemoF0 df;
    public DemoF1(DemoF0 df){
        this.df = df;
    }
    public void run(){
        System.out.println("aa");
        df.a(1);
    }
}
class DemoF2 extends Thread{
    private DemoF0 df;
    public DemoF2(DemoF0 df) {
        this.df = df;
    }
    @Override
    public void run() {
        System.out.println("bb");
        df.a(2);
    }
}
